package main

import (
	"fmt"
	"sync"
	"time"
)

//主角信息
type Protagonist struct {
	Name   string   //名字
	Memory []string //记忆
}

//女主
var LiShiQing *Protagonist

//女主待机模式信号
var LiSleep chan struct{}

//男主
var XiaoHeYun *Protagonist

//男主待机信号
var XiaoSleep chan struct{}

//故事剧情步骤
var Step int

//男女主联合剧情信号
var totalStory sync.WaitGroup

//初始化人物信息
func InitStory() {
	LiShiQing = &Protagonist{Name: "李诗情", Memory: make([]string, 0)}
	XiaoHeYun = &Protagonist{Name: "肖鹤云", Memory: make([]string, 0)}
	Step = 1
	XiaoSleep = make(chan struct{})
	LiSleep = make(chan struct{})
	go func() {
		XiaoSleep <- struct{}{}
		LiSleep <- struct{}{}
	}()
}

//剧情
// event 事件id
func StoryStep(event int) bool {
	switch event {
	case 1:
		return LiShiQingFirst()
	case 2:
		return LiShiQingReset()
	case 3:
		return XiaoHeYunReset()
	case 4:
		return LudiStory()
	case 5:
		return UncleMaStory()
	case 6:
		return UncleJiaoStory()
	case 7:
		return AuntGuoStory()
	case 8:
		return DriverStory()
	case 9:
		return PoliceZhangStory()
	case 10:
		return FindCriminal()
	case 11:
		return GameOver()
	default:
		return false
	}

}

//模拟实现开端剧情int

func ResetStart() {
	//判断故事还有后续
	if StoryStep(Step) {
		Step++
		ResetStart()
	}

	return
}

//李诗情第一次感受爆炸
func LiShiQingFirst() bool {
	totalStory.Add(1)
	//女主独立剧情
	go func() {
		<-LiSleep
		str := "第一天"
		//将故事写入记忆
		LiShiQing.Memory = append(LiShiQing.Memory, str)
		fmt.Println(str)

		str = "李诗情死于公交车爆炸"
		//将故事写入记忆
		LiShiQing.Memory = append(LiShiQing.Memory, str)
		time.Sleep(time.Second)
		fmt.Println(str)
		totalStory.Done()
	}()
	totalStory.Add(1)
	//男主独立剧情
	go func() {
		<-XiaoSleep
		totalStory.Done()
	}()

	totalStory.Wait()
	//男主待机模式
	go func() {
		XiaoSleep <- struct{}{}
	}()

	//女主待机模式
	go func() {
		LiSleep <- struct{}{}
	}()

	return true
}

//李诗情重生，拉男主下车
func LiShiQingReset() bool {
	totalStory.Add(1)
	//女主独立剧情
	go func() {
		str := "第二天"
		//将故事写入记忆
		LiShiQing.Memory = append(LiShiQing.Memory, str)
		time.Sleep(time.Second)
		fmt.Println(str)

		str = "李诗情拉男主下车"
		//将故事写入记忆
		LiShiQing.Memory = append(LiShiQing.Memory, str)
		time.Sleep(time.Second)
		fmt.Println(str)
		<-LiSleep
		totalStory.Done()
	}()
	totalStory.Add(1)
	//男主独立剧情
	go func() {
		<-XiaoSleep
		totalStory.Done()
	}()

	totalStory.Wait()
	//共同剧情
	str := "男主死于爆炸，女主进医院接收调查"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	fmt.Println(str)

	//男主待机模式
	go func() {
		XiaoSleep <- struct{}{}
	}()

	//女主待机模式
	go func() {
		LiSleep <- struct{}{}
	}()
	return true
}

//肖鹤云复活
func XiaoHeYunReset() bool {
	str := "第三天"
	//将故事写入记忆
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	totalStory.Add(1)
	//女主独立剧情
	go func() {
		<-LiSleep
		totalStory.Done()
	}()
	totalStory.Add(1)
	//男主独立剧情
	go func() {
		str := "由于男主被拉下车，记忆被激活"
		//将故事写入记忆
		LiShiQing.Memory = append(LiShiQing.Memory, str)
		LiShiQing.Memory = append(LiShiQing.Memory, str)
		time.Sleep(time.Second)
		fmt.Println(str)
		<-XiaoSleep
		totalStory.Done()
	}()

	totalStory.Wait()

	//共同剧情
	str = "男主砸玻璃，被肌肉男制服，公交车爆炸"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	//男主待机模式
	go func() {
		XiaoSleep <- struct{}{}
	}()

	//女主待机模式
	go func() {
		LiSleep <- struct{}{}
	}()
	return true
}

//卢迪故事线
func LudiStory() bool {
	totalStory.Add(1)
	//女主独立剧情
	go func() {
		<-LiSleep
		totalStory.Done()
	}()
	totalStory.Add(1)
	//男主独立剧情
	go func() {
		<-XiaoSleep
		totalStory.Done()
	}()

	totalStory.Wait()

	str := "第四天"
	//将故事写入记忆
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	//共同剧情
	str = "男女主寻找爆炸源，阻止卢迪上车"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "卢迪躲过爆炸和男女主成为朋友，并认同男女主因循环来拯救世界"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "男女主得知卢迪的小屋和暗号：卢•猫之使徒•哮喘征服者•被光选中的人•笛"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	//男主待机模式
	go func() {
		XiaoSleep <- struct{}{}
	}()

	//女主待机模式
	go func() {
		LiSleep <- struct{}{}
	}()
	return true
}

//马大伯西瓜故事线
func UncleMaStory() bool {
	totalStory.Add(1)
	//女主独立剧情
	go func() {
		<-LiSleep
		totalStory.Done()
	}()
	totalStory.Add(1)
	//男主独立剧情
	go func() {
		<-XiaoSleep
		totalStory.Done()
	}()

	totalStory.Wait()

	str := "第五天"
	//将故事写入记忆
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	//共同剧情
	str = "男主为确认炸药，踩碎马大伯西瓜发生争执"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "女主假装马大伯儿子同事，缓解矛盾"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "在公交车要爆炸之际解开马大伯与儿子心结"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	//男主待机模式
	go func() {
		str = "男主做了噩梦，进入待机模式，很久才醒来"
		XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
		time.Sleep(time.Second)
		fmt.Println(str)
		XiaoSleep <- struct{}{}
	}()

	//女主待机模式
	go func() {
		LiSleep <- struct{}{}
	}()
	return true
}

//焦叔故事线
func UncleJiaoStory() bool {
	str := "第六天"
	//将故事写入记忆
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	totalStory.Add(1)
	//女主独立剧情
	go func() {
		<-LiSleep
		totalStory.Done()
	}()
	totalStory.Add(1)
	//男主独立剧情
	go func() {
		<-XiaoSleep
		totalStory.Done()
	}()

	totalStory.Wait()

	//共同剧情
	str = "为确认焦叔身份，男主想直接拉焦叔下车"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "女主谎称没有卫生巾，焦书打开箱子给她卫生巾"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "男女主确认焦叔是好人，公交车依旧爆炸"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	//男主待机模式
	go func() {
		XiaoSleep <- struct{}{}
	}()

	//女主待机模式
	go func() {
		LiSleep <- struct{}{}
	}()
	return true
}

//锅姨故事线
func AuntGuoStory() bool {
	str := "第七天"
	//将故事写入记忆
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	totalStory.Add(1)
	//女主独立剧情
	go func() {
		<-LiSleep
		totalStory.Done()
	}()
	totalStory.Add(1)
	//男主独立剧情
	go func() {
		<-XiaoSleep
		totalStory.Done()
	}()

	totalStory.Wait()

	//共同剧情
	str = "为确锅姨身份，男主去抢锅，被锅姨引爆炸药"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "接下来苏醒后几次都是阻止锅姨，男主女主被刺杀"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "男女主再次循环，男主杀了锅姨，男女主下车逃跑，仍旧没有阻止爆炸"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	//男主待机模式

	go func() {
		str := "女主进入待机模式，男主把女主抱回屋子，独自等着警察到来，在警车上睡着了"
		XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
		fmt.Println(str)
		time.Sleep(time.Second)
		XiaoSleep <- struct{}{}
	}()

	//女主待机模式
	go func() {
		LiSleep <- struct{}{}
	}()
	return true
}

//Driver故事线
func DriverStory() bool {
	str := "第八天"

	time.Sleep(time.Second)
	fmt.Println(str)

	totalStory.Add(1)
	//女主独立剧情
	go func() {
		<-LiSleep
		LiShiQing.Memory = append(LiShiQing.Memory, "第八天")
		str := "女主独自醒来，发现男主身体状况也来越差，苏醒时间越来越慢"
		LiShiQing.Memory = append(LiShiQing.Memory, str)
		time.Sleep(time.Second)
		fmt.Println(str)
		totalStory.Done()
	}()
	totalStory.Add(1)
	//男主独立剧情
	go func() {
		<-XiaoSleep
		//将故事写入记忆
		XiaoHeYun.Memory = append(XiaoHeYun.Memory, "第八天")
		str := "男主醒来后，知道自己不是天选之人，要尽快辅助女主拯救乘客"
		XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
		time.Sleep(time.Second)
		fmt.Println(str)
		totalStory.Done()
	}()

	totalStory.Wait()

	//共同剧情
	str = "男女主用暗号说服卢迪，又假冒警察劝说焦叔帮忙"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "锅姨被控制住，女主劝说司机在桥边停车，司机不听"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "男女主发现锅姨和司机是夫妻，一起策划爆炸，炸药会在1：45准时定时爆炸"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	//男主待机模式
	go func() {
		XiaoSleep <- struct{}{}
	}()

	//女主待机模式
	go func() {
		LiSleep <- struct{}{}
	}()
	return true
}

//张警官故事线
func PoliceZhangStory() bool {
	str := "第九天"

	time.Sleep(time.Second)
	fmt.Println(str)

	totalStory.Add(1)
	//女主独立剧情
	go func() {
		<-LiSleep
		totalStory.Done()
	}()
	totalStory.Add(1)
	//男主独立剧情
	go func() {
		<-XiaoSleep
		totalStory.Done()
	}()

	totalStory.Wait()

	//共同剧情
	str = "男女主知道凭自己的能力无法阻止爆炸，所以在东路站下车，寻求警方帮助"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "在与张警官的沟通中知道张警官的手机号和警方遇到类似情况如何安排"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "男女主再次进入睡眠，等待新一轮循环"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	//男主待机模式
	go func() {
		XiaoSleep <- struct{}{}
	}()

	//女主待机模式
	go func() {
		LiSleep <- struct{}{}
	}()
	return true
}

//找出猥琐男
func FindCriminal() bool {
	str := "第十天"

	time.Sleep(time.Second)
	fmt.Println(str)

	totalStory.Add(1)
	//女主独立剧情
	go func() {
		<-LiSleep
		totalStory.Done()
	}()
	totalStory.Add(1)
	//男主独立剧情
	go func() {
		<-XiaoSleep
		totalStory.Done()
	}()

	totalStory.Wait()

	//共同剧情
	str = "男主人公苏醒时间推迟，女主将男主唤醒，男主出现衰弱反省，二人通过手机暗示卢迪和焦叔帮助"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "大家制止了锅姨引爆炸弹，但是炸弹有定时装置，司机不顾阻拦将车开到大桥"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "张警官接过炸弹，因为时间到了被炸死，男女主配合江警官查明了真相"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "当年王萌萌因为被公交车上的猥琐男猥亵，选择在桥上下车被撞死，后被网暴导致其父母心里产生问题"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "男女主找到曾经的目击者，目击者因害怕网暴选择沉默，但是将网盘链接结交给了男女主"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	str = "男主开始吐血，知道明天是最后一轮循环，自己可能不会醒来，将注意事项嘱托给女主，二人相拥"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	//男主待机模式
	go func() {
		time.Sleep(1)
		XiaoSleep <- struct{}{}
	}()

	//女主待机模式
	go func() {
		LiSleep <- struct{}{}
	}()
	return true
}

//大团圆结局
func GameOver() bool {
	str := "第十一天"

	time.Sleep(time.Second)
	fmt.Println(str)

	totalStory.Add(1)
	//女主独立剧情
	go func() {
		<-LiSleep
		LiShiQing.Memory = append(LiShiQing.Memory, "第十一天")
		str := "女主独自醒来，怎么呼唤男主也无法唤醒他，知道了他无法醒来，只能自己独自行动"
		LiShiQing.Memory = append(LiShiQing.Memory, str)
		time.Sleep(time.Second)
		fmt.Println(str)

		str = "女主通过手机暗示卢迪和焦书帮忙，在车上提前制止了锅姨，并发送信息给张警官，司机并未停车，将车开上了大桥"
		LiShiQing.Memory = append(LiShiQing.Memory, str)
		time.Sleep(time.Second)
		fmt.Println(str)

		str = "车上众人控制住锅姨，却忽略了司机，司机去拉炸药"
		LiShiQing.Memory = append(LiShiQing.Memory, str)
		time.Sleep(time.Second)
		fmt.Println(str)

		totalStory.Done()
	}()
	totalStory.Add(1)
	//男主独立剧情
	go func() {
		<-XiaoSleep
		//将故事写入记忆
		XiaoHeYun.Memory = append(XiaoHeYun.Memory, "第十一天")
		str := "此刻，男主醒来，发现司机要引爆炸药，将其抱住"
		XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
		time.Sleep(time.Second * 3)
		fmt.Println(str)
		totalStory.Done()
	}()

	totalStory.Wait()

	//共同剧情
	str = "警方已经在桥上提前做好布控，张警官将炸药扔到江水，无人员伤亡，猥琐男真凶被抓，车上乘客得到表彰，完美结局。"
	XiaoHeYun.Memory = append(XiaoHeYun.Memory, str)
	LiShiQing.Memory = append(LiShiQing.Memory, str)
	time.Sleep(time.Second)
	fmt.Println(str)

	//男主待机模式
	go func() {
		XiaoSleep <- struct{}{}
	}()

	//女主待机模式
	go func() {
		LiSleep <- struct{}{}
	}()
	return false
}
func main() {
	InitStory()
	ResetStart()
}
